//
// Created by Luhang on 2023/4/14/014.
//

#ifndef INC_0204DATA_CLASS_DATA_H
#define INC_0204DATA_CLASS_DATA_H

#endif //INC_0204DATA_CLASS_DATA_H

#include <iostream>
#include <cassert>

using namespace std;

class Data{
public:
    friend ostream& operator<<(ostream& out, const Data& d);
    friend istream& operator>>(istream& in, Data& d);

    Data(int year = 2023, int month = 4, int day = 14);

    Data(const Data& d){
        _year = d._year;
        _month = d._month;
        _day = d._day;
    }

    Data& operator=(const Data& d){
        if (*this != d){
            _year = d._year;
            _month = d._month;
            _day = d._day;
        }
        return *this;
    }

    ~Data(){
        _year = _month = _day = 0;
    }

    void Print() const{
        cout << _year << "-" << _month << "-" << _day << endl;
    }

    //d += day
    Data& operator+=(int day);

    //d + day
    Data operator+(int day)const;

    //d -= day
    Data& operator-=(int day);

    //d - day
    Data operator-(int day);

    bool operator==(const Data& d)const{
        return _year == d._year && _month == d._month && _day == d._day;
    }

    bool operator<(const Data& d)const{
        return _year < d._year || (_year == d._year && _month < d._month)
        || (_year == d._year && _month == d._month && _day < d._day);
    }

    bool operator<=(const Data& d)const{
        return *this == d || *this < d;
    }

    bool operator!=(const Data& d)const{
        return !(*this == d);
    }

    bool operator>(const Data& d)const{
        return !(*this <= d);
    }

    bool operator>=(const Data& d)const{
        return !(*this < d);
    }

    //d1 - d2
    int operator-(const Data& d)const;

    //++d
    Data& operator++();

    //d++
    //int参数，只是为了占位，构成重载，为了区分
    Data operator++(int);

    //--d
    Data& operator--();

    //d--
    Data operator--(int);

    //获取每个月的天数
    int GetMonthDay(int year, int month) const;

private:
    int _year;
    int _month;
    int _day;
};

inline ostream& operator<<(ostream& out, const Data& d){
    out << d._year << "-" << d._month << "-" << d._day << endl;
    return out;
}

//流输入时Data类对象不能加const，因为要改变
inline istream& operator>>(istream& in, Data& d){
    in >> d._year >> d._month >> d._day;
    return in;
}